package chooongg.base

import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import chooongg.base.annotation.ContentLayout
import chooongg.base.annotation.WindowBackground

/**
 * QuickActivity and QuickFragment initialize interface
 */
interface QuickPageInitialize {

    @LayoutRes
    fun initLayout(): Int = UNDEFINED_INT

    @DrawableRes
    fun windowBackground(): Int?

    /**
     * 初始化配置
     */
    fun initConfig(savedInstanceState: Bundle?)

    /**
     * 初始化内容加载
     */
    fun initContent(savedInstanceState: Bundle?)

    fun getContentLayout() = when {
        initLayout() != UNDEFINED_INT -> null
        javaClass.isAnnotationPresent(ContentLayout::class.java) ->
            javaClass.getAnnotation(ContentLayout::class.java)?.value
        else -> null
    }

    fun getWindowBackgroundRes() = when {
        windowBackground() != null -> windowBackground()
        javaClass.isAnnotationPresent(WindowBackground::class.java) ->
            javaClass.getAnnotation(WindowBackground::class.java)?.value
        else -> null
    }
}